#include "../src/CameraDriver/Virtual/Driver.hpp"
#include <chrono>
#include <iostream>
#include <spdlog/spdlog.h>
#include <stb/stb_image_write.h>
#include <thread>

int width, height, comp;

int main() {
  VirtualDriver driver;
  auto list = driver.GetCameraList();
  std::cout << "Camera Current : " << list[0].first << std::endl;
  BaseCamera *camera = list[0].second;
  camera->funcNewImage = [](long frameID, char *data,
                            const std::string &additional) {
    stbi_write_png(std::format("{}.png", frameID).c_str(), width, height, comp,
                   data, width);
  };
  auto config = camera->Config()->ItemList();
  std::cout << "Camera Config List" << std::endl;
  for (const auto &i : config)
    std::cout << "ID: " << i.id << " Describe: " << i.describe
              << " ReadOnly: " << i.readonly << std::endl;
  std::cout << std::endl;
  auto TypeInf = dynamic_cast<RealtimeCamera *>(camera)->ShotImageType();
  width = TypeInf.width;
  height = TypeInf.height;
  comp = [&TypeInf]() {
    switch (TypeInf.type) {
    case BaseCamera::ImageType::RGB8:
      return 3;
    case BaseCamera::ImageType::GREY:
      return 1;
    }
  }();
  std::cout << "StartShot <<<<<<" << std::endl;
  dynamic_cast<RealtimeCamera *>(camera)->StartShot();
  std::this_thread::sleep_for(std::chrono::seconds(5));
  std::cout << "StopShot >>>>>>" << std::endl;
}
